package com.handinfo.android.core.net;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.utils.Tools;

public class DWConnectionCreator implements Runnable
{
	public DWConnectionCreator()
	{
		m_state = WAIT;
		m_startTime = System.currentTimeMillis();
	}
	private int m_state;
	private long m_startTime;
	public void run()
	{
		try {
			DWGameManager.getInstance().openConnection();
			if(DWGameManager.getInstance().getConnection().isAlive()) {
				m_state = SUCCESS;
			}
			else {
				m_state = FAILED;
			}
		}
		catch (Exception e) {
			Tools.debug(e);
			m_state = FAILED;
		}
	}
	
	public int getState()
	{
		return m_state;
	}
	
	public long getLiveTime()
	{
		return System.currentTimeMillis() - m_startTime;
	}
	
	public static final int SUCCESS = 1;
	public static final int FAILED = 2;
	public static final int WAIT = 3;
	
	public static final int TIME_OUT = 10000;
}
